﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ChongJu.ImageAnalyze.Segmentation
{
    public class SegmentationClient
    {
        private IntPtr _iptr;
        private bool _init;

        public SegmentationClient()
        {
            _iptr = SegmentationSDK.CreateJY_Segmentation();
            _init = false;
        }

        public bool Init()
        {
            var bol = Set_Threshold();
            if (bol == false)
                return false;

            bol = Set_Img_Crop(10, 10, 10, 10);
            if (bol == false)
                return false;

            _init = false;
            return true;
        }

        private bool Set_Threshold()
        {
            return SegmentationSDK.Set_Threshold(_iptr, 50, 1000, 3);
        }

        private bool Set_Img_Crop(int x, int y, int w, int h)
        {
            return SegmentationSDK.Set_Img_Crop(_iptr, 100, 100, 100, 100);
        }

        public IntPtr Get_Segmentation_img(int _width, int _height, IntPtr input, int step, ref int newWidth, ref int newHeight, ref int newStep, ref double angle, ref int x1, ref int y1, ref int w1, ref int h1)
        {
            return SegmentationSDK.Get_Segmentation_img(_iptr,
                _width,
                _height,
                3,
                input,
                step,
                ref newWidth,
                ref newHeight,
                ref newStep,
                ref angle,
                ref x1,
                ref y1,
                ref w1,
                ref h1
                );
        }

        public bool White_Segmentation_img(int _width, int _height, IntPtr input, int step, IntPtr path, ref double angle, ref int x1, ref int y1, ref int w1, ref int h1)
        {
            return SegmentationSDK.White_Segmentation_img(_iptr,
                _width,
                _height,
                3,
                input,
                step,
                path,
                ref angle,
                ref x1,
                ref y1,
                ref w1,
                ref h1
                );
        }


        public void FreeImage(IntPtr data)
        {
            SegmentationSDK.FreeImage(data);
        }
    }
}
